<?php 
namespace App\Repositories;

use App\Models\Config;
use App\Models\ConfigGroup;
use App\Exceptions\InvalidException;
use DB;
class ConfigRepo  extends BaseRepo
{

	public function __construct()
   {
   	 parent::$model = new Config();
   }

	public function getList($group_id=0)
	{
		return Config::where(function($query)use($group_id){
			$query->where('group_id',$group_id);
		})->paginate(10)->toArray();
		
	}
	public function group()
	{
		return ConfigGroup::all()->toArray();
	}

	public function createConfig($data)
	{
		Config::create($data);
	}
	public function updateConfig($id,$data)
	{
		Config::where('id',$id)->update($data);
	}
	public function saveAllConfig($data) 
	{
		foreach($data as  $key=>$value) {
			Config::where('name',$key)->update(['value'=>$value]);
		}
	}
}